import com.baomidou.mybatisplus.generator.AutoGenerator;
import com.baomidou.mybatisplus.generator.config.DataSourceConfig;
import com.baomidou.mybatisplus.generator.config.GlobalConfig;
import com.baomidou.mybatisplus.generator.config.PackageConfig;
import com.baomidou.mybatisplus.generator.config.StrategyConfig;
import com.baomidou.mybatisplus.generator.config.rules.DbType;
import com.baomidou.mybatisplus.generator.config.rules.NamingStrategy;

public class Generator {
    private static String[] tableName = new String[]{"tb_role","tb_user_role","tb_menu","tb_role_menu"};


    public static void main(String[] args) {
        GlobalConfig config = new GlobalConfig();
        //1.全局配置
        config.setAuthor("wwz");
        config.setOutputDir("F:\\Workspaces\\IDEA\\mybatisplus\\src\\main\\java");
        config.setFileOverride(true);
        config.setServiceName("%sService"); //默认生成IEmployeeService格式的service   %s去掉I
        config.setBaseResultMap(true) ;   //是否生成基本结果集映射
        config.setBaseColumnList(true);  //是否生成数据库列 做通用查询列
        //2.数据源等配置
        DataSourceConfig dsConfig = new DataSourceConfig();
        dsConfig.setDbType(DbType.MYSQL);
        dsConfig.setDriverName("com.mysql.jdbc.Driver");
        dsConfig.setUrl("jdbc:mysql://localhost:3306/cloud?serverTimezone=Asia/Shanghai");
        dsConfig.setUsername("root");
        dsConfig.setPassword("root123456abc");
        //3.策略配置
        StrategyConfig strategyConfig = new StrategyConfig();
        strategyConfig.setCapitalMode(true); //开启全局大写命名
        strategyConfig.setNaming(NamingStrategy.underline_to_camel);  //数据库映射到实体类的命名策略
        strategyConfig.setTablePrefix(new String[]{"tb_"});
        strategyConfig.setInclude(tableName);//生成的表
        //4.包名策略
        PackageConfig packageConfig = new PackageConfig();
        packageConfig.setParent("com.wwz");
        packageConfig .setMapper("dao");
        packageConfig.setEntity("entity");
        packageConfig.setService("service");
        packageConfig.setController("controller");
        packageConfig .setXml("mapper");
        //5.整合配置
        AutoGenerator autoGenerator = new AutoGenerator();
        autoGenerator.setGlobalConfig(config);
        autoGenerator.setDataSource(dsConfig);
        autoGenerator.setPackageInfo(packageConfig);
        autoGenerator .setStrategy(strategyConfig);
        //6.执行
        autoGenerator.execute();



    }
}
